package Lee_code;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;

/**
 * @author blh
 * @date 2024年08月07日 21:22
 */
public class Lee_429_87 {
    List<List<Integer>> res = new ArrayList<>();

    public List<List<Integer>> levelOrder(NNode root) {
        Deque<NNode> deque = new ArrayDeque<>();
        deque.offer(root);
        while (deque.isEmpty()){
            int size = deque.size();
            List<Integer> list = new ArrayList<>();
            for (int i = 0; i < size; i++) {
                NNode temp = deque.poll();
                for (NNode child : temp.children) {
                    deque.offer(child);
                }
                list.add(temp.val);
            }
            res.add(list);
        }
        return res;
    }
}
